﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace TfsBacklogMgr.Tfs
{
    public enum ConnectionStatus
    {
        Offline,
        Connecting,
        Online,
        Error
    }

    public class ConnectionInfo
    {
        private ConnectionStatus _LastStatus;
        private string _TeamProject;
        private Uri _TeamProjectCollectionUri;

        public ConnectionStatus LastStatus
        {
            get { return _LastStatus; }
            set
            {
                _LastStatus = value;
            }
        }

        public string TeamProject
        {
            get { return _TeamProject; }
            set
            {
                _TeamProject = value;
            }
        }

        public Uri TeamProjectCollectionUri
        {
            get { return _TeamProjectCollectionUri; }
            set
            {
                _TeamProjectCollectionUri = value;
            }
        }

        #region Persistence

        public void SaveConnection()
        {
            if (_LastStatus == ConnectionStatus.Online)
            {
                //Registry.CurrentUser.SetValue("Software\\SuperOffice\\TFS-Spec-Link\\CollectionUri", _TeamProjectCollectionUri.ToString());
                //Registry.CurrentUser.SetValue("Software\\SuperOffice\\TFS-Spec-Link\\Project", _TeamProject);
            }
        }

        public static ConnectionInfo LoadConnection()
        {
            //object o = Registry.CurrentUser.GetValue("Software\\SuperOffice\\TFS-Spec-Link\\CollectionUri");
            //string collectionName = o as string;
            //o = Registry.CurrentUser.GetValue("Software\\SuperOffice\\TFS-Spec-Link\\Project");
            //string teamProjectName = o as string;
            //if (!string.IsNullOrEmpty(collectionName) && !string.IsNullOrEmpty(teamProjectName))
            //{
            //    Uri collectionUri = new Uri( collectionName );
            //    return new ConnectionInfo
            //    {
            //        TeamProjectCollectionUri = collectionUri,
            //        TeamProject = teamProjectName
            //    };
            //}
            return null;
        }
        #endregion

    }
}
